package org.xshop.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.xshop.core.JPush2Helper;
import org.xshop.mapper.TExpressMsgMapper;
import org.xshop.model.TExpressMsg;
import org.xshop.service.ITExpressMsgService;

import com.weibo.api.motan.config.springsupport.annotation.MotanService;

import top.ibase4j.core.base.BaseServiceImpl;
import top.ibase4j.core.util.ExceptionUtil;
import top.ibase4j.core.util.InstanceUtil;

/**
 * @author ShenHuaJie
 * @since 2018年6月21日 下午4:05:42
 */
@MotanService(interfaceClass = ITExpressMsgService.class)
@CacheConfig(cacheNames = "TExpressMsg")
public class ExpressMsgService extends BaseServiceImpl<TExpressMsg, TExpressMsgMapper>
implements ITExpressMsgService {
    @Autowired
    private JPush2Helper jpushHelper;

    @Override
    public TExpressMsg update(TExpressMsg record) {
        record = super.update(record);
        try {
            Map<String, String> extras = InstanceUtil.newHashMap();
            extras.put("type", "5");
            jpushHelper.sendNotificationAll("系统消息", "系统消息", extras);
        } catch (Exception e) {
            logger.error(ExceptionUtil.getStackTraceAsString(e));
        }
        mapper.insertMsg(record);
        return record;
    }

    @Override
    public void delete(Long id) {
        super.delete(id);
        Map<String, Object> param = InstanceUtil.newHashMap("msgId", id);
        mapper.deleteMsg(param);
    }

    @Override
    public void deleteMsg(Map<String, Object> param) {
        mapper.deleteMsg(param);
    }
}
